﻿using System;
using System.Text;

namespace YJKRevitAxisModule
{
	public static class CharAndNumberConvert
	{
		public static int Chr2AscII(string character)
		{
			if (character.Length == 1)
			{
				return (int)new ASCIIEncoding().GetBytes(character)[0];
			}
			throw new Exception("Character is not valid.");
		}

		public static string AscII2Chr(int asciiCode)
		{
			if (asciiCode >= 0 && asciiCode <= 255)
			{
				ASCIIEncoding asciiencoding = new ASCIIEncoding();
				byte[] bytes = new byte[]
				{
					(byte)asciiCode
				};
				return asciiencoding.GetString(bytes);
			}
			throw new Exception("ASCII Code is not valid.");
		}
	}
}
